{% extends "base.html" %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>Activity Management</h2>
        <a href="{{ url_for('organization_new_activity') }}" class="btn btn-primary">
            <i class="fas fa-plus"></i> Post New Activity
        </a>
    </div>

    <!-- Filters -->
    <div class="card mb-4">
        <div class="card-body">
            <form method="get" class="row g-3">
                <div class="col-md-3">
                    <label for="status" class="form-label">Activity Status</label>
                    <select name="status" id="status" class="form-select">
                        <option value="">All</option>
                        <option value="pending" {% if request.args.get('status') == 'pending' %}selected{% endif %}>Pending Review</option>
                        <option value="approved" {% if request.args.get('status') == 'approved' %}selected{% endif %}>Approved</option>
                        <option value="rejected" {% if request.args.get('status') == 'rejected' %}selected{% endif %}>Rejected</option>
                        <option value="completed" {% if request.args.get('status') == 'completed' %}selected{% endif %}>Completed</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <label for="date_range" class="form-label">Date Range</label>
                    <select name="date_range" id="date_range" class="form-select">
                        <option value="">All Time</option>
                        <option value="upcoming" {% if request.args.get('date_range') == 'upcoming' %}selected{% endif %}>Upcoming</option>
                        <option value="past" {% if request.args.get('date_range') == 'past' %}selected{% endif %}>Past</option>
                    </select>
                </div>
                <div class="col-md-3 d-flex align-items-end">
                    <button type="submit" class="btn btn-primary">Apply Filters</button>
                </div>
            </form>
        </div>
    </div>

    <!-- Activities Table -->
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Activity Name</th>
                            <th>Type</th>
                            <th>Status</th>
                            <th>Start Date</th>
                            <th>End Date</th>
                            <th>Registrations</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for activity in activities %}
                        <tr>
                            <td>{{ activity.title }}</td>
                            <td>{{ activity.category_text }}</td>
                            <td>
                                <span class="badge {% if activity.status == 'pending' %}bg-warning text-dark
                                      {% elif activity.status == 'approved' %}bg-success
                                      {% elif activity.status == 'rejected' %}bg-danger
                                      {% elif activity.status == 'completed' %}bg-info
                                      {% else %}bg-secondary{% endif %}">
                                    {% if activity.status == 'pending' %}Pending Review
                                    {% elif activity.status == 'approved' %}Approved
                                    {% elif activity.status == 'rejected' %}Rejected
                                    {% elif activity.status == 'completed' %}Completed
                                    {% else %}Unknown Status{% endif %}
                                </span>
                            </td>
                            <td>{{ activity.start_date.strftime('%Y-%m-%d') }}</td>
                            <td>{{ activity.end_date.strftime('%Y-%m-%d') }}</td>
                            <td>{{ activity.current_participants }}/{{ activity.max_participants }}</td>
                            <td>
                                <div class="btn-group">
                                    <a href="{{ url_for('activity_detail', activity_id=activity.id) }}" 
                                       class="btn btn-sm btn-info">View</a>
                                    {% if activity.status == 'pending' or activity.status == 'approved' %}
                                    <a href="{{ url_for('organization_edit_activity', activity_id=activity.id) }}" 
                                       class="btn btn-sm btn-primary">Edit</a>
                                    {% endif %}
                                    <a href="{{ url_for('organization_registrations', activity_id=activity.id) }}" 
                                       class="btn btn-sm btn-secondary">Manage Registrations</a>
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>

            <!-- Pagination -->
            <nav class="mt-3">
                <ul class="pagination justify-content-center">
                    {% if page > 1 %}
                    <li class="page-item">
                        <a class="page-link" href="{{ url_for('organization_activities', page=page-1, **request.args) }}">Previous</a>
                    </li>
                    {% endif %}
                    
                    <li class="page-item active">
                        <span class="page-link">{{ page }}</span>
                    </li>
                    
                    {% if has_next %}
                    <li class="page-item">
                        <a class="page-link" href="{{ url_for('organization_activities', page=page+1, **request.args) }}">Next</a>
                    </li>
                    {% endif %}
                </ul>
            </nav>
        </div>
    </div>
</div>
{% endblock %} 